package com.cndw.kungfu.model.pvp.war;

import com.cndw.kungfu.ext.LogUtil;
import com.cndw.kungfu.ext.TimeProcesser;
import com.cndw.kungfu.model.Context;
import com.cndw.kungfu.model.pvp.api.ApiCore;

public class WarCorePross implements Runnable {

	@Override
	public void run() {
		LogUtil.getMain().info("war pross suc ......");
		WarPross.runBoss();
		
		if (!ApiCore.isCrossServer()) {
			return;
		}
		LogUtil.getMain().info("war cross event init ....");
		WarCrossPross.runBoss();
		WarWorldPross.runBoss();
	}

	public static void main(String[] args) {
		int cycle = WarConfig.getCycle();
		System.out.println(cycle);

	}

	public synchronized static void runBoss() {
		
		WarCorePross corePross = new WarCorePross();
		corePross.run();
		int nextBegin = WarConfig.getSingleBegin() + WarConfig.cycleSeconeds;
		int initialDelay = nextBegin- TimeProcesser.getUnixTime();	
		initialDelay += 10;
		Context.getTimerServer().scheduleAtFixedRate(corePross, initialDelay, WarConfig.cycleSeconeds);
		
		LogUtil.getMain().info("war cycle next "+ TimeProcesser.getDateByUnixTime(nextBegin)+" delay "+(TimeProcesser.fromatTimeLength(initialDelay)));

	}

}
